import { EnumSchema } from '@/utils/common/types';
import { PresetColorEnum } from '@/enums/colorEnum';
import { useI18n } from '@/hooks/web/useI18n';

/** 数据权限操作枚举 */
export enum DataAuthOperationEnum {
  /** 读取 */
  Read = 1,
  /** 更新 */
  Update = 3,
  /** 删除 */
  Delete = 4,
}

/** 数据权限操作实体 */
export class DataAuthOperationEntity {
  /** 数据权限操作 */
  Operation: DataAuthOperationEnum;
  /** 显示描述 */
  Display: string;
  /** 颜色 */
  Color?: PresetColorEnum | string;

  constructor(operation: DataAuthOperationEnum, color?: PresetColorEnum | string) {
    const { t } = useI18n();
    this.Operation = operation;
    this.Color = color;
    switch (operation) {
      case DataAuthOperationEnum.Read:
        // this.Display = '读取';
        this.Display = t('enum.dataAuthOperation.read');
        this.Color = this.Color ? this.Color : PresetColorEnum.Green;
        break;
      case DataAuthOperationEnum.Update:
        // this.Display = '更新';
        this.Display = t('enum.dataAuthOperation.update');
        this.Color = this.Color ? this.Color : PresetColorEnum.Blue;
        break;
      case DataAuthOperationEnum.Delete:
        // this.Display = '删除';
        this.Display = t('enum.dataAuthOperation.delete');
        this.Color = this.Color ? this.Color : PresetColorEnum.Orange;
        break;
    }
  }
}

//#region 获取数据权限操作枚举架构
/**
 * 获取数据权限操作枚举架构
 */
export function getDataAuthOperationEnumSchema(enableTag = true): EnumSchema[] {
  const enumSchema: EnumSchema[] = [];
  const entities: DataAuthOperationEntity[] = [
    new DataAuthOperationEntity(DataAuthOperationEnum.Read),
    new DataAuthOperationEntity(DataAuthOperationEnum.Update),
    new DataAuthOperationEntity(DataAuthOperationEnum.Delete),
  ];
  entities.forEach((item) => {
    enumSchema.push({
      key: item.Operation as number,
      label: item.Display,
      value: item.Operation as number,
      tag: enableTag,
      tagColor: item.Color,
    });
  });
  return enumSchema;
}
//#endregion
